package org.jash.wechat2205.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

public class BitmapConvertFactory extends Converter.Factory {
    @Override
    public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
        if (type == Bitmap.class) {
            return new BitmapConvert();
        }
        return null;
    }
    private static class BitmapConvert implements Converter<ResponseBody, Bitmap> {

        @Override
        public Bitmap convert(ResponseBody responseBody) throws IOException {
            return BitmapFactory.decodeStream(responseBody.byteStream());
        }
    }
}
